/*
 ID:luongho3
 LANG:JAVA
 TASK:agrinet
 */
import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;


public class agrinet {

	public static int MAX = 200;
	public static int[][] m = new int[MAX][MAX];
	public static int N;
	public static int result;
	public static int INF = 1000000000;
	public static boolean[] mark = new boolean[MAX];
	public static int[] label = new int[MAX];
	
	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("agrinet.in"));
		PrintStream ps = new PrintStream(new File("agrinet.out"));
		System.setOut(ps);
		
		N = scanner.nextInt();
		for (int i=1;i<=N;++i) {
			for (int j=1;j<=N;++j) {
				m[i][j] = scanner.nextInt();
			}
		}
		
		for (int i=1;i<=N;++i) {
			mark[i] = false;
			label[i] = INF;
		}
		
		label[1] = 0;
		result = 0;
		for (int i=1;i<=N;++i) {
			int min = INF;
			int idx = -1;
			for (int j=1;j<=N;++j) {
				if (mark[j] == false && label[j] < min) {
					min = label[j];
					idx = j;
				}
			}
			if (idx == -1) {
				break;
			}
			mark[idx] = true;
			result += label[idx];
//			label[idx] = 0;
			for (int j=1;j<=N;++j) {
				if (j!=idx) {
					if (mark[j] == false) {
						if (m[idx][j] < label[j]) {
							label[j] = m[idx][j];
						}
					}
				}
			}
		}
		System.out.println(result);
		
		ps.close();
	}
	
}
